<template>
  <el-card shadow="navar">
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" size="medium" label-width="120px">
        <el-col :span="12">
          <el-form-item label="活动名称" prop="collectName">
            <el-input
              v-model.trim="formData.collectName"
              :disabled="disabled"
              placeholder="暂无"
              :maxlength="50"
              show-word-limit
              clearable
              :style="{ width: '100%' }"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="活动状态" prop="status">
            <el-select
              v-model="formData.status"
              placeholder="暂无"
              clearable
              :disabled="disabled"
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="item in dict.type.activity_status"
                :key="item.value"
                :label="item.label"
                :value="parseInt(item.value)"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="活动开始时间" prop="timeStart">
            <el-date-picker
              v-model.trim="formData.timeStart"
              :disabled="disabled"
              type="datetime"
              placeholder="暂无"
              :style="{ width: '100%' }"
              default-time="0:00:00"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="活动结束时间" prop="timeEnd">
            <el-date-picker
              v-model.trim="formData.timeEnd"
              :disabled="disabled"
              type="datetime"
              placeholder="暂无"
              :style="{ width: '100%' }"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="虚拟报名人数" prop="inventedEnrollNumber">
            <el-input
              v-model.trim="formData.inventedEnrollNumber"
              :disabled="disabled"
              placeholder="暂无"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="活动部门/门店">
            <el-input
              v-model.trim="formData.activityUnits"
              :disabled="disabled"
              placeholder="暂无"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="创建时间">
            <el-date-picker
              v-model.trim="formData.createTime"
              :disabled="disabled"
              type="datetime"
              placeholder="暂无"
              :style="{ width: '100%' }"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="创建人">
            <el-input
              v-model.trim="formData.createBy"
              :disabled="disabled"
              placeholder="暂无"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="修改时间">
            <el-input
              v-model.trim="formData.updateTime"
              :disabled="disabled"
              placeholder="暂无"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="修改人" prop="updateBy">
            <el-input
              v-model.trim="formData.updateBy"
              :disabled="disabled"
              placeholder="暂无"
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-divider></el-divider>
        </el-col>
        <el-col :span="12">
          <el-form-item label="活动封面" prop="coverImage">
            <el-image
              :src="getImgUrl(formData.coverImage)"
              lazy
              class="img"
              fit="contain"
            ></el-image>
          </el-form-item>
          <el-form-item label="详情封面" prop="detailImage">
            <el-image
              v-for="(item, index) in formData.detailImage.split(',')"
              :key="index"
              :src="getImgUrl(item)"
              lazy
              class="img"
              fit="contain"
            ></el-image>
          </el-form-item>
          <el-form-item label="分享封面" prop="shareImage">
            <el-image
              v-for="(item, index) in formData.shareImage.split(',')"
              :key="index"
              :src="getImgUrl(item)"
              lazy
              class="img"
              fit="contain"
            ></el-image>
          </el-form-item>
          <el-form-item label="活动描述" prop="collectContent">
            <editor
              v-model="formData.collectContent"
              :min-height="192"
              :readOnly="disabled"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button @click="goBack">取消</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </el-card>
</template>

<script>
import { getGatherById } from '@/api/activity/gather'
export default {
  dicts: ['activity_status'],
  data() {
    return {
      disabled: true,
      formData: {
        collectName: '',
        timeStart: '',
        timeEnd: '',
        inventedEnrollNumber: null,
        createTime: '',
        createBy: '',
        createTime: '',
        activityUnit: [],
        activityUnits: '',
        updateBy: '',
      },
    }
  },
  filters: {
    typeFilter(val, type) {
      if (val === null) return null
      let data = type.filter((item) => {
        return val == item.value
      })
      if (data.length) {
        return data[0].label
      } else {
        return val
      }
    },
  },
  computed: {},
  watch: {},
  mounted() {
    this.init()
  },
  methods: {
    init() {
      getGatherById({ id: this.$route.params.id }).then((res) => {
        this.formData = res.data
        this.formData.activityUnits = res.data.activityUnit.map((item) => {
          return item.applicableUnit
        })
      })
    },
    goBack() {
      this.$router.go(-1) // 返回
      //关闭子页面
      this.$store.state.tagsView.visitedViews.splice(
        this.$store.state.tagsView.visitedViews.findIndex(
          (item) => item.path === this.$route.path
        ),
        1
      )
      this.$router.push(
        this.$store.state.tagsView.visitedViews[
          this.$store.state.tagsView.visitedViews.length - 1
        ].path
      )
    },
  },
}
</script>
<style scoped>
.img {
  height: 254px;
  border: 1px solid #ddd;
  display: block;
  margin-bottom: 15px;
}
</style>
